package com.ayu.shortlink.admin.service.handler.filter;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.ayu.shortlink.admin.common.convention.exception.ClientException;
import com.ayu.shortlink.admin.common.enums.ChainBizMarkEnum;
import com.ayu.shortlink.admin.dto.req.CouponTemplateAddReqDTO;
import com.ayu.shortlink.admin.service.basics.filter.AbstractVerifyFilterChainHandler;
import org.springframework.stereotype.Component;

/**
 * 优惠券参数空值判断责任链
 */
@Component
public class CouponTemplateCreateParamNotNullChainFilter implements AbstractVerifyFilterChainHandler<CouponTemplateAddReqDTO> {

    @Override
    public void handler(CouponTemplateAddReqDTO requestParam) {
        if(StrUtil.isEmpty(requestParam.getName())){
            throw new ClientException("优惠券名称不能为空");
        }
        if(StrUtil.isEmpty(requestParam.getConsumeRule())){
            throw new ClientException("优惠券消耗规则不能为空");
        }
        if(StrUtil.isEmpty(requestParam.getReceiveRule())){
            throw new ClientException("优惠券获取规则不能为空");
        }
        if(ObjectUtil.isEmpty(requestParam.getValidStartTime())){
            throw new ClientException("优惠券起始时间不能为空");
        }
        if(ObjectUtil.isEmpty(requestParam.getValidEndTime())){
            throw new ClientException("优惠券结束时间不能为空");
        }
        if(ObjectUtil.isEmpty(requestParam.getSource())){
            throw new ClientException("优惠券来源不能为空");
        }
        if(ObjectUtil.isEmpty(requestParam.getStock())){
            throw new ClientException("优惠券库存不能为空");
        }
        if(ObjectUtil.isEmpty(requestParam.getTarget())){
            throw new ClientException("优惠券对象不能为空");
        }
        if(ObjectUtil.isEmpty(requestParam.getType())){
            throw new ClientException("优惠卷类型不能为空");
        }
    }

    @Override
    public String mark() {
        return ChainBizMarkEnum.MERCHANT_ADMIN_CREATE_COUPON_TEMPLATE_KEY.name();
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
